%{
    #include <stdio.h>
    #include "util.h"
    #include "errormsg.h"
    //typedef char *string;

    //int yylex(void); /* function prototype */
    void yyerror(char *s)
    {
        EM_error(EM_tokPos, "%s", s);
    }
%}


%union {
	int ipos;
	int ival;
	string sval;
}

%token <sval> ID STRING
%token <ival> INT

%token <ipos> 
    COMMA COLON SEMICOLON DOT
    LPAREN RPAREN LBRACK RBRACK LBRACE RBRACE  
    PLUS MINUS TIMES DIVIDE EQ NEQ LT LE GT GE
    AND OR
    ASSIGN ARRAY IF THEN ELSE WHILE FOR TO DO LET IN END OF BREAK
    NIL
    TYPE FUNCTION VAR 

%start program

%%

program: 
      token program {}
    | token {}
    ;

token: 
      ID      {printf("tokpos:NaN,tok:%s\n",$1);}
    | STRING  {printf("tokpos:NaN,tok:%s\n",$1);}
    | INT     {printf("tokpos:NaN,tok:%d\n",$1);}
    | COMMA   {printf("tokpos:%d,tok:,\n",$1);}
    | COLON   {printf("tokpos:%d,tok::\n",$1);}
    | SEMICOLON{printf("tokpos:%d,tok:;\n",$1);}
    | DOT     {printf("tokpos:%d,tok:.\n",$1);}
    | LPAREN  {printf("tokpos:%d,tok:}\n",$1);}
    | RPAREN  {printf("tokpos:%d,tok:(\n",$1);}
    | LBRACK  {printf("tokpos:%d,tok:[\n",$1);}
    | RBRACK  {printf("tokpos:%d,tok:]\n",$1);}
    | LBRACE  {printf("tokpos:%d,tok:{\n",$1);}
    | RBRACE  {printf("tokpos:%d,tok:}\n",$1);}
    | PLUS    {printf("tokpos:%d,tok:+\n",$1);}
    | MINUS   {printf("tokpos:%d,tok:-\n",$1);}
    | TIMES   {printf("tokpos:%d,tok:*\n",$1);}
    | DIVIDE  {printf("tokpos:%d,tok:/\n",$1);}
    | EQ      {printf("tokpos:%d,tok:==\n",$1);}
    | NEQ     {printf("tokpos:%d,tok:!=\n",$1);}
    | LT      {printf("tokpos:%d,tok:<\n",$1);}
    | LE      {printf("tokpos:%d,tok:<=\n",$1);}
    | GT      {printf("tokpos:%d,tok:>\n",$1);}
    | GE      {printf("tokpos:%d,tok:>=\n",$1);}
    | AND     {printf("tokpos:%d,tok:&&\n",$1);}
    | OR      {printf("tokpos:%d,tok:||\n",$1);}
    | ASSIGN  {printf("tokpos:%d,tok::=\n",$1);}
    | ARRAY   {printf("tokpos:%d,tok:array\n",$1);}
    | IF      {printf("tokpos:%d,tok:if\n",$1);}
    | THEN    {printf("tokpos:%d,tok:then\n",$1);}
    | ELSE    {printf("tokpos:%d,tok:else\n",$1);}
    | WHILE   {printf("tokpos:%d,tok:while\n",$1);}
    | FOR     {printf("tokpos:%d,tok:for\n",$1);}
    | TO      {printf("tokpos:%d,tok:to\n",$1);}
    | DO      {printf("tokpos:%d,tok:do\n",$1);}
    | LET     {printf("tokpos:%d,tok:let\n",$1);}
    | IN      {printf("tokpos:%d,tok:in\n",$1);}
    | END     {printf("tokpos:%d,tok:end\n",$1);}
    | OF      {printf("tokpos:%d,tok:of\n",$1);}
    | BREAK   {printf("tokpos:%d,tok:break\n",$1);}
    | NIL     {printf("tokpos:%d,tok:nil\n",$1);}
    | TYPE    {printf("tokpos:%d,tok:type\n",$1);}
    | FUNCTION{printf("tokpos:%d,tok:function\n",$1);}
    | VAR     {printf("tokpos:%d,tok:var\n",$1);}

	
